﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Milan;

namespace milaninstaller
{
	/// <summary>
	/// This class downloads the 
	/// </summary>
	public class Downloader
	{
		/// <summary>
		/// Instantiates a downloader object
		/// </summary>
		/// <param name="productDirectory">Uses this parent product directory</param>
		public Downloader(string productDirectory)
		{
			m_productDirectory = productDirectory;
		}
		/// <summary>
		/// When scenario is localuseronly
		/// </summary>
		/// <returns></returns>
		public static string DefaultLocalUserDirectory()
		{
			return System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Apps", Settings.CompanyName, Settings.ProductName);
		}
		/// <summary>
		/// When scenario is with admin installer.
		/// </summary>
		/// <returns></returns>
		public static string DefaultGetAllUsersProgramDirectory()
		{
			return System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), Settings.CompanyName, Settings.ProductName);
		}
		public void Download()
		{
			Milan.Deploy.Client client = new Milan.Deploy.Client();
			client.Download(Milan.Settings.ProductVersion, m_productDirectory, Milan.Deploy.ReleaseType.Last);
			client.InstallationDirectory = Path.Combine(m_productDirectory,Milan.Deploy.Client.FormatVersionDirectory(Milan.Settings.ProductVersion));
			client.UpgradeNow();
			client.ReportInstallation();
		}
		private string m_productDirectory;
	}
}
